package mssql;

import java.io.File;
import java.sql.Connection;

import org.firefly.db.util.DBInfo;
import org.firefly.db.util.DBName;
import org.firefly.db.util.DBUtil;


public class EDUV8 {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		Class.forName("net.sourceforge.jtds.jdbc.Driver");
//		Class.forName("com.mysql.jdbc.Driver");
//		Class.forName("oracle.jdbc.driver.OracleDriver");
		Connection srcConn = java.sql.DriverManager.getConnection("jdbc:jtds:sqlserver://172.16.1.5:1433/RDSYSEDUV8", "sa", "Ep123!@#");
//		Connection tarConn = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:49183:xe", "RDSYSEDUV8", "eplugger");
//        Connection tarConn = java.sql.DriverManager.getConnection("jdbc:mysql://172.16.1.14:3306/RDSYSEDUV8?useUnicode=true&characterEncoding=utf-8&autoReconnect=true", "RDSYSEDUV8", "eplugger");
    
		try {
			DBInfo srcInfo = new DBInfo(srcConn, null, DBName.SqlServer2005);
//			DBInfo tarInfo = new DBInfo(tarConn, null, DBName.Mysql);
//			DBInfo tarInfo = new DBInfo(tarConn, "RDSYSEDUV8", DBName.Oracle);
//			DBUtils.dbConvertA2B(srcInfo, tarInfo, true);
			
			DBUtil.dbConvertA2SqlFile(srcInfo, new File("/Users/firefly/Desktop/init.sql"));
//			File saveFile = new File("/Users/firefly/Desktop/test.sql");
//	        FileOutputStream fos = new FileOutputStream(saveFile);
//	        OutputStreamWriter osw = new OutputStreamWriter(fos);
//	        
//			DBUtil.exportUpdateSQL(srcInfo, srcInfo.getDialect(), osw, new String[]{"SYS_MODULE"}, "where id='2c90810a4ddb0d2e014ddb10a04e0002'", false);
//			DBUtil.exportUpdateSQL(srcInfo, srcInfo.getDialect(), osw, new String[]{"SYS_AUTHORITY"}, "where beanId='zXProject'", true);
			/*导出表*/
//			FileOutputStream fos = new FileOutputStream("/Users/firefly/Desktop/a.sql");
//			OutputStreamWriter osw = new OutputStreamWriter(fos);
//			DBUtils.expertInsertSQL(srcInfo, srcInfo.getDialect(), osw, new String[]{"CFG_CATEGORY_ENTRY"}, "where id='2c90813c5ab71d12015ab71f70fe0003'", true);
			
			/*转移表*/
//			DBUtils.tableConvertA2B(srcInfo, tarInfo, new String[]{"CFG_CATEGORY","CFG_CATEGORY_ENTRY","CFG_CATEGORY_MAPPING","DM_AREA","DM_CHECK","DM_QUICK_SEARCH","SYS_AUTHORITY","SYS_BUSINESS_FILTER","SYS_BUSINESS_FILTER_RESULT","SYS_CFG_EDIT_TABLE","SYS_CFG_EXPORT","SYS_CFG_FORM","SYS_CFG_SCENE","SYS_CFG_SQL_TABLE","SYS_CFG_STAT","SYS_CFG_TABLE","SYS_CONCURRENT","SYS_ENTITY_META","SYS_GROUP","SYS_MENU","SYS_MODULE","SYS_PARAM"});
//			DBUtils.tableConvertA2B(srcInfo, tarInfo, new String[]{"SYS_MENU"});
//			DBUtils.tableConvertA2B(srcInfo, tarInfo, new String[]{"SYS_GROUP"});
			
			/*比较*/
//			FileOutputStream fos = new FileOutputStream("/Users/firefly/Desktop/a.sql");
//			OutputStreamWriter osw = new OutputStreamWriter(fos);
//			DBUtils.compareDB(srcInfo, tarInfo, osw, true);
			
			/*导出insert sql */
//			FileOutputStream fos = new FileOutputStream("/Users/firefly/Desktop/EADPV5.2.sql");
//			OutputStreamWriter osw = new OutputStreamWriter(fos);
////			DBUtils.expertInsertSQL(tarInfo, tarInfo.getDialect(), osw, new String[]{"SYS_CFG_EDIT_TABLE","SYS_CFG_EXPORT","SYS_CFG_FORM","SYS_CFG_SCENE","SYS_CFG_SQL_TABLE","SYS_CFG_STAT","SYS_CFG_TABLE","SYS_ENTITY_META"}, null, true);
//			DBUtils.expertInsertSQL(tarInfo, tarInfo.getDialect(), osw, null, null, true);
			
//			DBUtils.compareDB(srcInfo, tarInfo, osw, true);
//			File sqlFile = new File("/Users/firefly/Desktop/eadp5_1.sql");
//			DBUtils.dbConvertA2SqlFile(srcInfo, sqlFile);
		} finally{
			srcConn.close();
//			tarConn.close();
		}
	}

}
